Skip to content

fix(pinia-orm): apply casts before field type validation on save#2029

Merged
CodeDredd merged 1 commit into
mainfrom
fix/cast-before-validation
Jul 19, 2026
Merged

fix(pinia-orm): apply casts before field type validation on save#2029
CodeDredd merged 1 commit into
mainfrom
fix/cast-before-validation

Conversation

@CodeDredd

Copy link
Copy Markdown
Owner

Bug

When saving, casts for the set operation were applied after $fillField(). The attribute type check therefore validated the raw input and logged spurious warnings like

[Pinia ORM] Field notes:organization_id - 10191 is not a number

even though the cast (e.g. NumberCast) converts the value immediately afterwards and the store ends up with the correct value (#2003).

Fix

Apply the cast before the field is filled, so type validation sees the casted value. Values that fall back to the attribute default (input undefined) still pass through the cast after filling — unchanged behavior. Side effect worth noting: when a field has both a set-mutator and a cast, the mutator now receives the casted value (cast → mutate instead of mutate-after-cast) — this mirrors the get path (mutate → cast) symmetrically.

Tests

New regression test: @Cast(() => NumberCast) @Num(null) field saved with a string value must not warn and must store the number. Fails before, passes after. Full suite green (402 tests).

fixes #2003

Casts for the 'set' operation ran after $fillField, so the type check
warned about the raw input value (e.g. 'Field notes:organization_id -
10191 is not a number') even though the cast converts it right after.

The cast now runs before the field is filled, so validation sees the
casted value. Values filled from the attribute default still pass
through the cast afterwards, as before.

fixes #2003
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.40%. Comparing base (7a32aec) to head (f05e932).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2029      +/-   ##
==========================================
- Coverage   99.43%   99.40%   -0.04%     
==========================================
  Files          82       82              
  Lines        3022     3025       +3     
  Branches      530      533       +3     
==========================================
+ Hits         3005     3007       +2     
- Misses         14       15       +1     
  Partials        3        3              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@CodeDredd
CodeDredd merged commit 018acee into main Jul 19, 2026
12 of 13 checks passed
@CodeDredd
CodeDredd deleted the fix/cast-before-validation branch July 19, 2026 21:27
@github-actions github-actions Bot mentioned this pull request Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Casts do not appear to work when using pinia-orm-axios plugin

2 participants